package com.j256.ormlite.android.apptools;

import com.j256.ormlite.db.DatabaseType;
import com.j256.ormlite.db.SqliteAndroidDatabaseType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.DatabaseFieldConfig;
import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;
import com.j256.ormlite.table.DatabaseTableConfig;
import com.j256.ormlite.table.DatabaseTableConfigLoader;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Writer;
import java.lang.reflect.Field;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class OrmLiteConfigUtil
{
  protected static final String RAW_DIR_NAME = "raw";
  protected static final String RESOURCE_DIR_NAME = "res";
  private static final DatabaseType databaseType = new SqliteAndroidDatabaseType();
  protected static int maxFindSourceLevel = 20;

  private static boolean classHasAnnotations(Class<?> paramClass)
  {
    while (paramClass != null)
    {
      if (paramClass.getAnnotation(DatabaseTable.class) != null);
      while (true)
      {
        return true;
        try
        {
          Field[] arrayOfField = paramClass.getDeclaredFields();
          int i = arrayOfField.length;
          for (int j = 0; ; j++)
          {
            if (j >= i)
              break label117;
            Field localField = arrayOfField[j];
            if ((localField.getAnnotation(DatabaseField.class) != null) || (localField.getAnnotation(ForeignCollectionField.class) != null))
              break;
          }
        }
        catch (Throwable localThrowable1)
        {
          System.err.println("Could not load get delcared fields from: " + paramClass);
          System.err.println("     " + localThrowable1);
          return false;
        }
      }
      try
      {
        label117: Class localClass = paramClass.getSuperclass();
        paramClass = localClass;
      }
      catch (Throwable localThrowable2)
      {
        System.err.println("Could not get super class for: " + paramClass);
        System.err.println("     " + localThrowable2);
        return false;
      }
    }
    return false;
  }

  // ERROR //
  private static void findAnnotatedClasses(List<Class<?>> paramList, File paramFile, int paramInt)
    throws SQLException, IOException
  {
    // Byte code:
    //   0: aload_1
    //   1: invokevirtual 98	java/io/File:listFiles	()[Ljava/io/File;
    //   4: astore_3
    //   5: aload_3
    //   6: arraylength
    //   7: istore 4
    //   9: iconst_0
    //   10: istore 5
    //   12: iload 5
    //   14: iload 4
    //   16: if_icmpge +336 -> 352
    //   19: aload_3
    //   20: iload 5
    //   22: aaload
    //   23: astore 6
    //   25: aload 6
    //   27: invokevirtual 102	java/io/File:isDirectory	()Z
    //   30: ifeq +25 -> 55
    //   33: iload_2
    //   34: getstatic 19	com/j256/ormlite/android/apptools/OrmLiteConfigUtil:maxFindSourceLevel	I
    //   37: if_icmpge +12 -> 49
    //   40: aload_0
    //   41: aload 6
    //   43: iload_2
    //   44: iconst_1
    //   45: iadd
    //   46: invokestatic 104	com/j256/ormlite/android/apptools/OrmLiteConfigUtil:findAnnotatedClasses	(Ljava/util/List;Ljava/io/File;I)V
    //   49: iinc 5 1
    //   52: goto -40 -> 12
    //   55: aload 6
    //   57: invokevirtual 107	java/io/File:getName	()Ljava/lang/String;
    //   60: ldc 109
    //   62: invokevirtual 115	java/lang/String:endsWith	(Ljava/lang/String;)Z
    //   65: ifeq -16 -> 49
    //   68: aload 6
    //   70: invokestatic 119	com/j256/ormlite/android/apptools/OrmLiteConfigUtil:getPackageOfClass	(Ljava/io/File;)Ljava/lang/String;
    //   73: astore 7
    //   75: aload 7
    //   77: ifnonnull +32 -> 109
    //   80: getstatic 56	java/lang/System:err	Ljava/io/PrintStream;
    //   83: new 58	java/lang/StringBuilder
    //   86: dup
    //   87: invokespecial 59	java/lang/StringBuilder:<init>	()V
    //   90: ldc 121
    //   92: invokevirtual 65	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   95: aload 6
    //   97: invokevirtual 68	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   100: invokevirtual 72	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   103: invokevirtual 78	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   106: goto -57 -> 49
    //   109: aload 6
    //   111: invokevirtual 107	java/io/File:getName	()Ljava/lang/String;
    //   114: astore 8
    //   116: aload 8
    //   118: iconst_0
    //   119: aload 8
    //   121: invokevirtual 125	java/lang/String:length	()I
    //   124: ldc 109
    //   126: invokevirtual 125	java/lang/String:length	()I
    //   129: isub
    //   130: invokevirtual 129	java/lang/String:substring	(II)Ljava/lang/String;
    //   133: astore 9
    //   135: new 58	java/lang/StringBuilder
    //   138: dup
    //   139: invokespecial 59	java/lang/StringBuilder:<init>	()V
    //   142: aload 7
    //   144: invokevirtual 65	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   147: ldc 131
    //   149: invokevirtual 65	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   152: aload 9
    //   154: invokevirtual 65	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   157: invokevirtual 72	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   160: astore 10
    //   162: aload 10
    //   164: invokestatic 135	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   167: astore 12
    //   169: aload 12
    //   171: invokestatic 137	com/j256/ormlite/android/apptools/OrmLiteConfigUtil:classHasAnnotations	(Ljava/lang/Class;)Z
    //   174: ifeq +12 -> 186
    //   177: aload_0
    //   178: aload 12
    //   180: invokeinterface 143 2 0
    //   185: pop
    //   186: aload 12
    //   188: invokevirtual 147	java/lang/Class:getDeclaredClasses	()[Ljava/lang/Class;
    //   191: astore 14
    //   193: aload 14
    //   195: arraylength
    //   196: istore 15
    //   198: iconst_0
    //   199: istore 16
    //   201: iload 16
    //   203: iload 15
    //   205: if_icmpge -156 -> 49
    //   208: aload 14
    //   210: iload 16
    //   212: aaload
    //   213: astore 17
    //   215: aload 17
    //   217: invokestatic 137	com/j256/ormlite/android/apptools/OrmLiteConfigUtil:classHasAnnotations	(Ljava/lang/Class;)Z
    //   220: ifeq +12 -> 232
    //   223: aload_0
    //   224: aload 17
    //   226: invokeinterface 143 2 0
    //   231: pop
    //   232: iinc 16 1
    //   235: goto -34 -> 201
    //   238: astore 11
    //   240: getstatic 56	java/lang/System:err	Ljava/io/PrintStream;
    //   243: new 58	java/lang/StringBuilder
    //   246: dup
    //   247: invokespecial 59	java/lang/StringBuilder:<init>	()V
    //   250: ldc 149
    //   252: invokevirtual 65	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   255: aload 6
    //   257: invokevirtual 68	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   260: invokevirtual 72	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   263: invokevirtual 78	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   266: getstatic 56	java/lang/System:err	Ljava/io/PrintStream;
    //   269: new 58	java/lang/StringBuilder
    //   272: dup
    //   273: invokespecial 59	java/lang/StringBuilder:<init>	()V
    //   276: ldc 80
    //   278: invokevirtual 65	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   281: aload 11
    //   283: invokevirtual 68	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   286: invokevirtual 72	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   289: invokevirtual 78	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   292: goto -243 -> 49
    //   295: astore 13
    //   297: getstatic 56	java/lang/System:err	Ljava/io/PrintStream;
    //   300: new 58	java/lang/StringBuilder
    //   303: dup
    //   304: invokespecial 59	java/lang/StringBuilder:<init>	()V
    //   307: ldc 151
    //   309: invokevirtual 65	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   312: aload 12
    //   314: invokevirtual 68	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   317: invokevirtual 72	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   320: invokevirtual 78	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   323: getstatic 56	java/lang/System:err	Ljava/io/PrintStream;
    //   326: new 58	java/lang/StringBuilder
    //   329: dup
    //   330: invokespecial 59	java/lang/StringBuilder:<init>	()V
    //   333: ldc 80
    //   335: invokevirtual 65	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   338: aload 13
    //   340: invokevirtual 68	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   343: invokevirtual 72	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   346: invokevirtual 78	java/io/PrintStream:println	(Ljava/lang/String;)V
    //   349: goto -300 -> 49
    //   352: return
    //
    // Exception table:
    //   from	to	target	type
    //   162	169	238	java/lang/Throwable
    //   186	198	295	java/lang/Throwable
    //   208	232	295	java/lang/Throwable
  }

  protected static File findRawDir(File paramFile)
  {
    for (int i = 0; (paramFile != null) && (i < 20); i++)
    {
      File localFile = findResRawDir(paramFile);
      if (localFile != null)
        return localFile;
      paramFile = paramFile.getParentFile();
    }
    return null;
  }

  private static File findResRawDir(File paramFile)
  {
    for (File localFile : paramFile.listFiles())
      if ((localFile.getName().equals("res")) && (localFile.isDirectory()))
      {
        File[] arrayOfFile2 = localFile.listFiles(new FileFilter()
        {
          public boolean accept(File paramAnonymousFile)
          {
            return (paramAnonymousFile.getName().equals("raw")) && (paramAnonymousFile.isDirectory());
          }
        });
        if (arrayOfFile2.length == 1)
          return arrayOfFile2[0];
      }
    return null;
  }

  private static String getPackageOfClass(File paramFile)
    throws IOException
  {
    BufferedReader localBufferedReader = new BufferedReader(new FileReader(paramFile));
    try
    {
      String[] arrayOfString;
      do
      {
        String str1;
        do
        {
          str1 = localBufferedReader.readLine();
          if (str1 == null)
            return null;
        }
        while (!str1.contains("package"));
        arrayOfString = str1.split("[ \t;]");
      }
      while ((arrayOfString.length <= 1) || (!arrayOfString[0].equals("package")));
      String str2 = arrayOfString[1];
      return str2;
    }
    finally
    {
      localBufferedReader.close();
    }
  }

  public static void main(String[] paramArrayOfString)
    throws Exception
  {
    if (paramArrayOfString.length != 1)
      throw new IllegalArgumentException("Main can take a single file-name argument.");
    writeConfigFile(paramArrayOfString[0]);
  }

  public static void writeConfigFile(File paramFile)
    throws SQLException, IOException
  {
    writeConfigFile(paramFile, new File("."));
  }

  public static void writeConfigFile(File paramFile1, File paramFile2)
    throws SQLException, IOException
  {
    ArrayList localArrayList = new ArrayList();
    findAnnotatedClasses(localArrayList, paramFile2, 0);
    writeConfigFile(paramFile1, (Class[])localArrayList.toArray(new Class[localArrayList.size()]));
  }

  public static void writeConfigFile(File paramFile, Class<?>[] paramArrayOfClass)
    throws SQLException, IOException
  {
    System.out.println("Writing configurations to " + paramFile.getAbsolutePath());
    writeConfigFile(new FileOutputStream(paramFile), paramArrayOfClass);
  }

  public static void writeConfigFile(OutputStream paramOutputStream, File paramFile)
    throws SQLException, IOException
  {
    ArrayList localArrayList = new ArrayList();
    findAnnotatedClasses(localArrayList, paramFile, 0);
    writeConfigFile(paramOutputStream, (Class[])localArrayList.toArray(new Class[localArrayList.size()]));
  }

  public static void writeConfigFile(OutputStream paramOutputStream, Class<?>[] paramArrayOfClass)
    throws SQLException, IOException
  {
    BufferedWriter localBufferedWriter = new BufferedWriter(new OutputStreamWriter(paramOutputStream), 4096);
    try
    {
      writeHeader(localBufferedWriter);
      int i = paramArrayOfClass.length;
      for (int j = 0; j < i; j++)
        writeConfigForTable(localBufferedWriter, paramArrayOfClass[j]);
      System.out.println("Done.");
      return;
    }
    finally
    {
      localBufferedWriter.close();
    }
  }

  public static void writeConfigFile(String paramString)
    throws SQLException, IOException
  {
    ArrayList localArrayList = new ArrayList();
    findAnnotatedClasses(localArrayList, new File("."), 0);
    writeConfigFile(paramString, (Class[])localArrayList.toArray(new Class[localArrayList.size()]));
  }

  public static void writeConfigFile(String paramString, Class<?>[] paramArrayOfClass)
    throws SQLException, IOException
  {
    File localFile = findRawDir(new File("."));
    if (localFile == null)
    {
      System.err.println("Could not find raw directory which is typically in the res directory");
      return;
    }
    writeConfigFile(new File(localFile, paramString), paramArrayOfClass);
  }

  private static void writeConfigForTable(BufferedWriter paramBufferedWriter, Class<?> paramClass)
    throws SQLException, IOException
  {
    String str = DatabaseTableConfig.extractTableName(paramClass);
    ArrayList localArrayList = new ArrayList();
    Object localObject = paramClass;
    if (localObject != null);
    while (true)
    {
      int j;
      try
      {
        Field[] arrayOfField = ((Class)localObject).getDeclaredFields();
        int i = arrayOfField.length;
        j = 0;
        if (j < i)
        {
          Field localField = arrayOfField[j];
          DatabaseFieldConfig localDatabaseFieldConfig = DatabaseFieldConfig.fromField(databaseType, str, localField);
          if (localDatabaseFieldConfig == null)
            break label230;
          localArrayList.add(localDatabaseFieldConfig);
          break label230;
        }
        Class localClass = ((Class)localObject).getSuperclass();
        localObject = localClass;
      }
      catch (Error localError)
      {
        System.err.println("Skipping " + paramClass + " because we got an error finding its definition: " + localError.getMessage());
        return;
      }
      if (localArrayList.isEmpty())
      {
        System.out.println("Skipping " + paramClass + " because no annotated fields found");
        return;
      }
      DatabaseTableConfigLoader.write(paramBufferedWriter, new DatabaseTableConfig(paramClass, str, localArrayList));
      paramBufferedWriter.append("#################################");
      paramBufferedWriter.newLine();
      System.out.println("Wrote config for " + paramClass);
      return;
      label230: j++;
    }
  }

  private static void writeHeader(BufferedWriter paramBufferedWriter)
    throws IOException
  {
    paramBufferedWriter.append('#');
    paramBufferedWriter.newLine();
    paramBufferedWriter.append("# generated on ").append(new SimpleDateFormat("yyyy/MM/dd hh:mm:ss").format(new Date()));
    paramBufferedWriter.newLine();
    paramBufferedWriter.append('#');
    paramBufferedWriter.newLine();
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.j256.ormlite.android.apptools.OrmLiteConfigUtil
 * JD-Core Version:    0.6.2
 */